<template>
  <div>
    <a-radio-group
      v-if="data?.length > 0"
      :options="data"
      v-model:value="modelValue"
      v-bind="$attrs"
      @change="emit('change')"
    ></a-radio-group>
    <div v-else class="text-gray-400">没有数据</div>
  </div>
</template>

<script setup lang="ts">
import { DICT_ENUM } from '@/enum/system';
import { getDictList } from '@/utils/common/dict';
import type { LabeledValue } from 'ant-design-vue/es/select';

const emit = defineEmits(['change']);
const data = ref<LabeledValue[]>([]);
const { t } = useI18n();
const modelValue = defineModel('modelValue');
const props = defineProps<{
  dict: DICT_ENUM;
}>();

const getData = async () => {
  let result = await getDictList(props.dict);
  data.value = result.map(e => {
    e.label = t(e.label);
    return e;
  });
};

onMounted(() => {
  getData();
});
</script>

<style lang="scss" scoped></style>
